package com.daoeping.action;

import java.util.ArrayList;
import java.util.List;

import com.daoeping.data.Bzn_questionfavgroup;
import com.daoeping.data.Bzn_questionfavorite;
import com.daoeping.data.Usr_user;
import com.daoeping.domain.JsonData;
import com.daoeping.service.Bzn_questionfavgroupService;
import com.daoeping.service.Bzn_questionfavoriteService;
import com.daoeping.util.ConverntJsonData;
import com.opensymphony.xwork2.ActionContext;

public class Bzn_questionfavgroupAction {
	private Bzn_questionfavorite bzn_questionfavorite ;
	private Bzn_questionfavgroup bzn_questionfavgroup ;
	private Bzn_questionfavoriteService bzn_questionfavoriteService;
	private Bzn_questionfavgroupService bzn_questionfavgroupService;
	private JsonData jsonData;
	
	public JsonData getJsonData() {
		return jsonData;
	}

	public void setJsonData(JsonData jsonData) {
		this.jsonData = jsonData;
	}

	public Bzn_questionfavorite getBzn_questionfavorite() {
		return bzn_questionfavorite;
	}

	public void setBzn_questionfavorite(Bzn_questionfavorite bzn_questionfavorite) {
		this.bzn_questionfavorite = bzn_questionfavorite;
	}

	public Bzn_questionfavgroup getBzn_questionfavgroup() {
		return bzn_questionfavgroup;
	}

	public void setBzn_questionfavgroup(Bzn_questionfavgroup bzn_questionfavgroup) {
		this.bzn_questionfavgroup = bzn_questionfavgroup;
	}

	public Bzn_questionfavoriteService getBzn_questionfavoriteService() {
		return bzn_questionfavoriteService;
	}

	public void setBzn_questionfavoriteService(
			Bzn_questionfavoriteService bzn_questionfavoriteService) {
		this.bzn_questionfavoriteService = bzn_questionfavoriteService;
	}

	public Bzn_questionfavgroupService getBzn_questionfavgroupService() {
		return bzn_questionfavgroupService;
	}

	public void setBzn_questionfavgroupService(
			Bzn_questionfavgroupService bzn_questionfavgroupService) {
		this.bzn_questionfavgroupService = bzn_questionfavgroupService;
	}

	public String addBzn_questionfavgroup(){
		if(!bzn_questionfavgroupService.addBzn_questionfavgroup(bzn_questionfavgroup)){
			return "exception";
		}
		bzn_questionfavorite = new Bzn_questionfavorite();
		bzn_questionfavorite.setBzn_questionfavgroup(bzn_questionfavgroup);
		bzn_questionfavorite.setUsr_user((Usr_user)ActionContext.getContext().getSession().get("user"));
		List<String> list = new ArrayList<String>();
		if(bzn_questionfavoriteService.addBzn_questionfavorite(bzn_questionfavorite)){
			list.add("success");
			jsonData = new JsonData();
			jsonData.setJsonData(new ConverntJsonData().getJsonData(list).toString());
			return "addBzn_questionfavgroup";
		}else{
			return "exception";
		}
	}
	
	public String findBzn_questionfavgroupList(){
		if(bzn_questionfavorite==null){
			bzn_questionfavorite = new Bzn_questionfavorite();
		}
		bzn_questionfavorite.setUsr_user((Usr_user)ActionContext.getContext().getSession().get("user"));
		jsonData = bzn_questionfavgroupService.findBzn_questionfavgroupList(bzn_questionfavorite);
		return "findBzn_questionfavgroupList";
	}
	
	public String editBzn_questionfavgroup(){
		List<String> list = new ArrayList<String>();
		if(bzn_questionfavgroupService.editBzn_questionfavgroup(bzn_questionfavgroup)){
			list.add("success_edit");
			jsonData = new JsonData();
			jsonData.setJsonData(new ConverntJsonData().getJsonData(list).toString());
			return "editBzn_questionfavgroup";
		}
			return "exception";
	}
	
	public String delBzn_questionfavgroup(){
		//empty favorite group id of favorite
		//del
		List<String> list = new ArrayList<String>();
		if(bzn_questionfavoriteService.editBzn_questionfavorite(jsonData)&&bzn_questionfavoriteService.delBzn_questionfavoriteByFavGroupId(bzn_questionfavgroup)&&bzn_questionfavgroupService.delBzn_questionfavgroup(bzn_questionfavgroup)){
			list.add("success_del");
			jsonData.setJsonData(new ConverntJsonData().getJsonData(list).toString());
			return "delBzn_questionfavgroup";
		}else{
			return "exception";
		}
		
	}
	
}
